import Chart from './chart';
import $ from 'jquery';
import * as com from './common';
import * as opt from './option';
import Node, {Type} from "./base";

const name = 'bar';
const image = 'barBase.png';

function getOption () {
  let option = {
    title: {
      text: '柱状图'
    },
    xAxis: {
      type: 'category',
      max: 'dataMax',
      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
    },
    yAxis: {
      min: -10,
      type: 'value'
    },
    grid: {},
    series: [{
      data: [820, 932, 901, 934, 1290, 1330, 1320],
      type: 'bar',
    }],
    _series: {
      label: opt.getLabel(),
      itemStyle: $.extend(opt.ItemStyle(), {barBorderRadius: 0})
    }
  };
  $.extend(option.title, opt.getTitle());
  $.extend(option.grid, opt.getGrid());
  $.extend(option.yAxis, opt.getAxis(0));
  $.extend(option.xAxis, opt.getAxis(1));

  com.SyncSeries(option);
  return option;
}

function getStyle (option) {
  let style = com.GetStyle(option);
  // style[1].children = style[1].children.push()com.ItemStyleExtraBar(option._series.itemStyle));
  style[1].children.push(new Node('边框圆角', 'barBorderRadius', option._series.itemStyle), Type.Value);
  return style;
}

function draw (id, option) {
  if (!option) option = getOption();
  com.SyncSeries(option);
  Chart.draw(id, option, name);
}

const Bar = {
  name: name,
  image: image,
  getOption: getOption,
  getStyle: getStyle,
  draw: draw
};

Chart.register(name, Bar);

export default Bar;
